package com.otaku.config;

import com.otaku.interceptor.DemoInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 标题：BaseConfig<br>
 * 功能说明：<br>
 * 系统版本：v1.0<br>
 * 开发人员： ganxiang20970 <br>
 * 开发时间：2018年04月17日 18:40<br>
 */
@Configuration
public class BaseConfig implements WebMvcConfigurer {

    @Override
    //静态资源配置
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/templates/**")
                .addResourceLocations("classpath:/templates/");
    }

    //拦截器创建
    @Bean
    public DemoInterceptor demoInterceptor() {
        return new DemoInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截器配置
        registry.addInterceptor(demoInterceptor());
    }
}
